﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using OAuthClient.Models;
using RuoVea.OAuthClient;
using System.Diagnostics;
using System.Net.Http;

namespace OAuthClient.Controllers
{
    public class HomeController : Controller
    {
        private readonly IHttpClientFactory _httpClientFactory;
        private readonly IOptions<OAuthClientConfig> _oauthClientConfig;
        private readonly ILogger<HomeController> _logger;

        public HomeController(IHttpClientFactory httpClientFactory, ILogger<HomeController> logger, IOptions<OAuthClientConfig> oauthClientConfig)
        {
            _httpClientFactory = httpClientFactory;
            _oauthClientConfig = oauthClientConfig;
            _logger = logger;
        }

        public IActionResult Index()
        {
            return View();
        }

        //[HttpGet("oauth/callback")]
        //public void sss() {
        //    var tty = "";
        //}

        [Authorize]
        public IActionResult Privacy()
        {
            var claims = HttpContext.User.Claims.ToList();

            ViewBag.claims = claims;
            return View();
        }

        //[HttpGet("/sign-out")]
        //public async Task<IActionResult> Logout()
        //{
        //    return await HttpContext.SignOutOAuthAsync(CookieAuthenticationDefaults.AuthenticationScheme);
        //}

        //public async Task<IActionResult> info(AuthClient client)
        //{
        //    var name = HttpContext.User.FindFirstValue("name");
        //  string info=await  client.GetInfo(name);
        //    ViewBag.info = info;
        //    return View();
        //}
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }
    }
}
